import 'package:flutter/material.dart';
import 'package:flutter_mwm/widget/widget.dart';

class RadioGroup<T> extends StatefulWidget {
  final T value;
  final T groupValue;
  final ValueChanged<T> onChanged;
  final Color activeColor;
  final Widget child;

  const RadioGroup(
      {@required this.value,
      @required this.groupValue,
      @required this.onChanged,
      this.activeColor,
      this.child});

  @override
  State<StatefulWidget> createState() {
    return _RadioGroupState();
  }
}

class _RadioGroupState extends State<RadioGroup> {
  @override
  Widget build(BuildContext context) {
    return ClickLayout(
      onPressed: _update,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Radio(
            activeColor: Colors.amber,
            value: widget.value,
            groupValue: widget.groupValue,
            onChanged: widget.onChanged,
          ),
          _child()
        ],
      ),
    );
  }

  Widget _child() {
    /*TextView(
      'VIN(车架号)查询',
      textColor: Colors.black,
      textSize: 18.0,
    )*/
    return null == widget.child ? Text('') : widget.child;
  }

  _update() {
    if (null != widget.onChanged) {
      widget.onChanged(widget.value);
    }
  }
}
